package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.TestUserMapper;
import com.itheima.pojo.Menu;
import com.itheima.pojo.TestUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = TestUserService.class)
@Transactional
public class TestUserServiceImpl implements TestUserService{


    @Autowired
    TestUserMapper testUserMapper;


    @Override
    public List<TestUser> findAll() {
        return testUserMapper.findAll();
    }

    @Override
    public List<Menu> findAllMenu() {
        //先查询所有的一级菜单
        List<Menu> meunOne = testUserMapper.findOneMenu();

        //循环一级菜单查询一级菜单下面的二级
        for (Menu menu : meunOne) {
            List<Menu> meunTwo = testUserMapper.findMenuByParentId(menu.getId());
            menu.setChildren(meunTwo);
        }

        return meunOne;
    }
}
